const constant = {
  navList: [],
};

document.addEventListener('DOMContentLoaded', () => {
    const asideWrap = document.querySelector('.aside-ul');
  
    // 绑定事件处理器到父元素
    asideWrap.addEventListener('click', (event) => {
      const target = event.target;
      if (target.tagName.toLowerCase() === 'li') {
        const id = target.getAttribute('data-id');
        window.location.replace(`?id=${id}`);
      }
    });
  
    axios.get('/files')
      .then(res => {
        console.log(res);
        if (res.data.code === 200) {
          const list = res.data.data;
          console.log(list);
          list.forEach(item => {
            console.log(item);
            const li = document.createElement('li');
            li.textContent = item.name.replace(/\.md/g, ''); // 设置文本内容
            li.className = 'aside-item'; // 添加类名
            li.setAttribute('data-id', item.id); // 添加 data-id 属性存储 ID
            asideWrap.appendChild(li); // 将 li 元素添加到 aside 中
            console.log(asideWrap);
          });
        }
      })
      .catch(error => {
        console.error('Error fetching files:', error);
      });
  });